#include<bits/stdc++.h>
using namespace std;

#define int long long 

const int N = 1e5 + 5;

int n,m,l,maxv;

struct node{
    int d,v,a;
}t[N];

int pos[N];

void solve()
{
    cin >> n >> m >> l >> maxv;
    bool flagA = 1;
    for(int i = 1;i <= n;i++)
    {
        cin >> t[i].d >> t[i].v >> t[i].a;
        if(t[i].a != 0)
            flagA = 0;
    }
    int maxn = 0;
    for(int i = 1;i <= m;i++)
        cin >> pos[i],maxn = max(maxn,pos[i]);
    if(flagA == 1)
    {
        int cnt = 0;
        int q2 = 0;
        for(int i = 1;i <= n;i++)
        {
            if(t[i].v > maxv && t[i].d <= maxn)
            {
                cnt++;
                q2 = 1;
            }
        }
        cout << cnt << " " << q2 << endl;
        return;
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    // freopen("detect.in","r",stdin);
    // freopen("detect.out","w",stdout);
    int Test_case=1;
    cin >> Test_case;
    while(Test_case--)solve();
    return 0;
}